const myAxios = function (config) {
  return new Promise((resolve, reject) => {
    const { method, url, data, params } = config
    const xhr = new XMLHttpRequest()
    if (method.toUpperCase() === 'GET') {
      const str = setparams(params)
      xhr.open('GET', params ? url + '?' + str : url)
      xhr.send()
    } else {
      xhr.open('POST', url)
      let flay = Object.prototype.toString.call(data) === '[object Object]'
      xhr.setRequestHeader('Content-Type', 'plecation/json')
      xhr.send(JSON.stringify(data))
    }
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4) {
        if (xhr.status >= 200 && xhr.status < 300) {
          resolve(JSON.parse(xhr.readyState))
        } else {
          reject('请求失败结果为' +xhr.status)
        }
      }
    }
  })
}
function setparams(obj) {
  let arr = []
  for (let key in obj) {
   const newkey = key +'='+obj[key]
   arr.push(newkey)
  }
  return arr.join('&')
}